﻿#include "stdafx.h"
#include "CShapeEx.h"
using namespace std;

//-------------------------------------------------------------------------
// IMPLEMENTATION CLASS
//-------------------------------------------------------------------------

/** 
 * CShapeEx includes follwing functions: 
	1. Constructor

	2. SetInfor (full args)
	3. Set Color: pen or brush color
	4. Set width or pattern
	5. Set style
	6. Set filled or not filled
	7. Set cordinates

	8. GetInfor (full args)
	9. Get Color: pen or brush color
	10. Get width or pattern
	11. Get style
	12. Get filled or not filled
	13. Get cordinates. 
	
	14. Move
	15. View
	16. IsInShape(POINT) //do nothing. Click chon
	17. IsInsShape (POINT, POINT) . Quet chon
 */

/* 1. Constructor */
CShapeEx::CShapeEx()
{
	left		= 0;
	top			= 0;
	right		= 0;
	bottom		= 0;
	filled		= false;
	penWidth	= 1;
	penStyle	= PS_SOLID;
	brushColor	= RGB(0, 0, 0);
	penColor	= RGB(0, 0, 0);
	pattern		= _RECTANGLE_;
}

/* 2. SetInfor (full arg)*/
void CShapeEx::SetInfor(int _left, int _top, int _right, int _bottom, bool _filled,
						int _penWidth, int _penStyle, COLORREF _brushColor, COLORREF _penColor,
						int _pattern)
{
	left		= _left;
	top			= _top;
	right		= _right;
	bottom		= _bottom;
	filled		= _filled;
	penWidth	= _penWidth;
	penStyle	= _penStyle;
	brushColor	= _brushColor;
	penColor	= _penColor;
	pattern		= _pattern;
}

/* 3. SetInfor COlor */
void CShapeEx::SetInfor(int _type, COLORREF _color)
{
	switch (_type)
	{
		case _BRUSHCOLOR_:
			brushColor = _color;
			break;

		case _PENCOLOR_:
			penColor = _color;
			break;

		default:
				break;	//do nothing
	}	
}

/* 5. SetInfor width or pattern */
void CShapeEx::SetInfor(int _type, int _value)
{
	switch (_type)
	{
		case _PENWIDTH_:
			penWidth = _value;
			break;

		case _PATTERN_:
			pattern = _value;
			break;

		case _PENSTYLE_:
			penStyle = _value;
			break;

		default:
				break;	//do nothing
	}
}

/* 7 SetInfor filled or not filled */ 
void CShapeEx::SetInfor(bool _filled)
{
	filled = _filled;
}

/* 8. SetInfor cordinate */
void CShapeEx::SetInfor(int _left, int _top, int _right, int _bottom)
{
	left	= _left;
	top		= _top;
	right	= _right;
	bottom	= _bottom;
}

/* 9. GetInfor (full arguments)*/
void CShapeEx::GetInfor(int& _left, int& _top, int& _right, int& _bottom, bool& _filled,
						int& _penWidth, int& _penStyle, COLORREF& _brushColor, COLORREF& _penColor,
						int& _pattern)
{
	_left		= left;
	_top		= top;
	_right		= right;
	_bottom		= bottom;
	_filled		= filled;
	_penWidth	= penWidth;
	_penStyle	= penStyle;
	_brushColor	= brushColor;
	_penColor	= penColor;
	_pattern	= pattern;
}

/* 10. Get Color */
void CShapeEx::GetInfor(int _type, COLORREF& _color)
{
	switch (_type)
	{
		case _BRUSHCOLOR_:
			_color = brushColor;
			break;

		case _PENCOLOR_:
			_color = penColor;
			break;

		default:
				break;	//do nothing
	}
}

/* 11. Get pattern or width */
void CShapeEx::GetInfor(int _type, int& _value)
{
	switch (_type)
	{
		case _PENWIDTH_:
			_value = penWidth;
			break;

		case _PATTERN_:
			_value = pattern;

		default:
				break;	//do nothing
	}
}

/* 12. Get Pen style */
void CShapeEx::GetInfor(int& _penstyle)
{
	penStyle = _penstyle;
}

/* 13. Get filled */
void CShapeEx::GetInfor(bool& _filled)
{
	_filled = filled;
}

/* 14. Get cordinate */
void CShapeEx::GetInfor(int& _left, int& _top, int& _right, int& _bottom)
{
	_left		= left;
	_top		= top;
	_right		= right;
	_bottom		= bottom;
}

/* 15. Move */ 
void CShapeEx::Move(int dx, int dy)
{
	left	+= dx;
	top		+= dy;
	right	+= dx;
	bottom	+= dy;
}

/* 16. IsInShape (POINT */
// {
		//do nothing . Moi loai shape co cach chon khac nhau 
//	}

/* 17. IsInShape (POINT, POINT) */
bool CShapeEx::IsInShape(POINT point1, POINT point2)
{
	return ((point1.x <= left) && (point1.y <= top) &&
			(point2.x >= right) && (point2.y >= bottom));
}

/* 18. isResizing */
int CShapeEx::isResizing(POINT)
{
	return -1;
}

/* 19. Resize() */
void CShapeEx::Resize(int newx, int newy, int position)
{
	switch (position)
	{
		case _LEFTTOP_:
			left = newx;
			top = newy;
			break;

		case _LEFTBOTTOM_:
			left = newx;
			bottom = newy;
			break;

		case _RIGHTTOP_:
			right = newx;
			top = newy;
			break;

		case _RIGHTBOTTOM_:
			right = newx;
			bottom = newy;
			break;

		case _MIDDLELEFTRIGHTTOP_:
			top = newy;
			break;

		default:
				break;	//do nothing
	}
}